package cn.seocoo.platform.common.utils.jpush;

import cn.seocoo.platform.common.exception.BusinessException;

import java.util.LinkedHashMap;
import java.util.Map;

//import com.alibaba.fastjson.annotation.JSONType;

/**
 * 消息通知类型
 * @author KongXianDe
 * @date 2018/12/25 17:56
 */
//@JSONType(serializeEnumAsJavaBean = true)
public enum MessageTypeEnum {

    /**
     * 聚合支付订单消息
     */
    ORDER(1, "聚合支付订单消息"),
    /**
     * 聚合支付系统消息
     */
    SYSTEM(2, "聚合支付系统消息"),
    /**
     * 新零售订单消息
     */
    NEWSALEORDER(3, "新零售订单消息"),
    /**
     * 新零售系统消息
     */
    NEWSALESYSTEM(4, "新零售系统消息");

    private int code;
    private String desc;
    private String name;

    MessageTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<Integer, MessageTypeEnum> BY_VALUE_MAP = new LinkedHashMap<>();

    static {
        for (MessageTypeEnum messageTypeEnum : MessageTypeEnum.values()) {
            BY_VALUE_MAP.put(messageTypeEnum.getCode(), messageTypeEnum);
        }
    }

    /**
     * 根据code查询对应的外卖类型枚举
     */
    public static MessageTypeEnum convertCode2Enum(int code) throws BusinessException {
        if (!BY_VALUE_MAP.containsKey(code)) {
            throw new BusinessException("枚举对应的code" + code + "不存在");
        }
        return BY_VALUE_MAP.get(code);
    }

    /**
     * 根据枚举name查询对应的外卖类型枚举
     */
    public static MessageTypeEnum convertStr2Enum(String str) throws BusinessException {
        try {
            return MessageTypeEnum.valueOf(str);
        } catch (Exception e) {
            throw new BusinessException("枚举对应常量" + str + "不存在");
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getName() {
        return this.name();
    }
}
